/***************************************************************************
 *   Copyright (C) 2008 by Eduardo Gurgel Pinho                            *
 *   edgurgel@gmail.com                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
***************************************************************************/

#include "scene_tree.h"

#include <algorithm>
#include <typeinfo>

namespace Ui {

Scene_Tree::Scene_Tree(QWidget* _parent) : QTreeWidget(_parent), scene(0) {
	headerItem()->setText(0,tr("Attribute"));
	headerItem()->setText(1, tr("Value"));
	connect(this,SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(update_scene(QTreeWidgetItem*,int)));
}

Scene_Tree::~ Scene_Tree(void) {

}

QSize Scene_Tree::minimumSizeHint() const {
	return QSize(250,150);
}

void Scene_Tree::show_information(QTreeWidgetItem *_item, int _column) {
	QTreeWidgetItem* parent = _item->parent();
	if(parent != 0) {
		switch(parent->type()) {
			case objects_type: {
				int id = _item->child(0)->text(1).toUInt();
				emit material_selected(scene->get_object(id)->get_material());
				emit object_selected(scene->get_object(id));
				break;
			}
			case lights_type: {
				int id = _item->child(0)->text(1).toUInt();
				emit material_selected(scene->get_light(id)->get_material());
			}
			default: 
				break;
		}
	}
}

void Scene_Tree::update_scene(QTreeWidgetItem *_item, int _column) {
	QTreeWidgetItem* parent = _item->parent();
	switch(parent->type()) {
		case scene_type:{
			/* Scene::ambient */
			if(parent->child(0) == _item) {
				double ambient = _item->text(1).toDouble();
				scene->set_ambient(ambient);
			}
			else if(parent->child(1) == _item) {
				double attenuation_a = _item->text(1).toDouble();
				double attenuation_b = scene->get_attenuation_value(2);
				double attenuation_c = scene->get_attenuation_value(3);
				scene->set_attenuation(attenuation_a,attenuation_b,attenuation_c);
			} else if(parent->child(2) == _item) {
				double attenuation_a = scene->get_attenuation_value(1);
				double attenuation_b = _item->text(1).toDouble();
				double attenuation_c = scene->get_attenuation_value(3);
				scene->set_attenuation(attenuation_a,attenuation_b,attenuation_c);
			} else if(parent->child(3) == _item) {
				double attenuation_a = scene->get_attenuation_value(1);
				double attenuation_b = scene->get_attenuation_value(2);
				double attenuation_c = _item->text(1).toDouble();
				scene->set_attenuation(attenuation_a,attenuation_b,attenuation_c);
			}
			
			break;
		}
		case objects_type:{
		
			break;
		}
		case lights_type:{
			
			break;
		}
		case sphere_type:{
			/* Sphere::radius */
			double radius = _item->text(1).toDouble();
			unsigned int id = parent->child(0)->text(1).toUInt();
			Sirat::Object::Sphere* sphere = static_cast<Sirat::Object::Sphere*>(scene->get_object(id));
			sphere->set_radius(radius);
			break;
		}
		case plane_type:{
			break;
		}
		case disc_type:{
			/* Disc::radius */
			double radius = _item->text(1).toDouble();
			unsigned int id = parent->child(0)->text(1).toUInt();
			Sirat::Object::Disc* disc = static_cast<Sirat::Object::Disc*>(scene->get_object(id));
			disc->set_radius(radius);
			break;
		}
		case cone_type:{
			unsigned int id = parent->child(0)->text(1).toUInt();
			Sirat::Object::Cone* cone = static_cast<Sirat::Object::Cone*>(scene->get_object(id));
			if(_item == parent->child(1)) {
				/* Cone::radius */
				double radius = _item->text(1).toDouble();
				cone->set_radius(radius);
			}
			else if(_item == parent->child(2)) {
				/* Cone::height */
				double height = _item->text(1).toDouble();
				cone->set_height(height);
			}
			break;
		}
		case cylinder_type:{
			unsigned int id = parent->child(0)->text(1).toUInt();
			Sirat::Object::Cylinder* cylinder = static_cast<Sirat::Object::Cylinder*>(scene->get_object(id));
			if(_item == parent->child(1)) {
				/* Cylinder::radius */
				double radius = _item->text(1).toDouble();
				cylinder->set_radius(radius);
			}
			else if(_item == parent->child(2)) {
				/* Cylinder::height */
				double height = _item->text(1).toDouble();
				cylinder->set_height(height);
			}
			break;
		}
		case color_type:{
			/* Color::r,g,b */
			double r,g,b;
			r = std::min(1.0,std::max(0.0,parent->child(0)->text(1).toDouble()));
			g = std::min(1.0,std::max(0.0,parent->child(1)->text(1).toDouble()));
			b = std::min(1.0,std::max(0.0,parent->child(2)->text(1).toDouble()));
			
			switch(parent->parent()->type()) {
				case scene_type: {
					scene->set_background(Sirat::Common::Color(r,g,b));
					break;
				}
				default: break;
			}
			break;
		}
		case vector_type:{
			/* Vector::x,y,z */
			double x,y,z;
			x = parent->child(0)->text(1).toDouble();
			y = parent->child(1)->text(1).toDouble();
			z = parent->child(2)->text(1).toDouble();
			switch(parent->parent()->type()) {
				case sphere_type: {
					/* Sphere::center */
					if(parent == parent->parent()->child(2)) {
						unsigned int id = parent->parent()->child(0)->text(1).toUInt();
						Sirat::Object::Sphere* sphere = static_cast<Sirat::Object::Sphere*>(scene->get_object(id));
						sphere->set_center(Sirat::Math::Vector(x,y,z));
					} 
					break;
				}
				case plane_type: {
					unsigned int id = parent->parent()->child(0)->text(1).toUInt();
					Sirat::Object::Plane* plane = static_cast<Sirat::Object::Plane*>( scene->get_object(id));
					/* Plane::point */
					if(parent == parent->parent()->child(1)) {
						plane->set_point(Sirat::Math::Vector(x,y,z));							
					}
					/* Plane::normal */
					else if(parent == parent->parent()->child(2)) {
						plane->set_normal(Sirat::Math::Vector(x,y,z));
					}
					break;
				}
				case disc_type: {
					unsigned int id = parent->parent()->child(0)->text(1).toUInt();
					Sirat::Object::Disc* disc = static_cast<Sirat::Object::Disc*>( scene->get_object(id));
					/* Disc::center */
					if(parent == parent->parent()->child(2)) {
						disc->set_center(Sirat::Math::Vector(x,y,z));							
					}
					/* Disc::normal */
					else if(parent == parent->parent()->child(3)) {
						disc->set_normal(Sirat::Math::Vector(x,y,z));
					}
					break;
				}
				case cone_type: {
					unsigned int id = parent->parent()->child(0)->text(1).toUInt();
					Sirat::Object::Cone* cone = static_cast<Sirat::Object::Cone*>( scene->get_object(id));
					/* Cone::center */
					if(parent == parent->parent()->child(3)) {						
						cone->set_center(Sirat::Math::Vector(x,y,z));							
					}
					/* Cone:direction */
					else if(parent == parent->parent()->child(4)) {
						cone->set_direction(Sirat::Math::Vector(x,y,z));
					}
					break;
				}
				case cylinder_type: {
					unsigned int id = parent->parent()->child(0)->text(1).toUInt();
					Sirat::Object::Cylinder* cylinder = static_cast<Sirat::Object::Cylinder*>( scene->get_object(id));
					/* Cylinder::center */
					if(parent == parent->parent()->child(3)) {						
						cylinder->set_center(Sirat::Math::Vector(x,y,z));							
					}
					/* Cylinder:direction */
					else if(parent == parent->parent()->child(4)) {
						cylinder->set_direction(Sirat::Math::Vector(x,y,z));
					}
					break;
				}
				case triangle_type: {
					unsigned int id = parent->parent()->child(0)->text(1).toUInt();
					Sirat::Object::Triangle* triangle = static_cast<Sirat::Object::Triangle*>( scene->get_object(id));
					/* Triangle::vertex0 */
					if(parent == parent->parent()->child(1)) {
						unsigned short index = 0;
						triangle->set_vertex(Sirat::Math::Vector(x,y,z),index);
					}
					/* Triangle::vertex1 */
					else if(parent == parent->parent()->child(2)) {
						unsigned short index = 1;
						triangle->set_vertex(Sirat::Math::Vector(x,y,z),index);
					}
					/* Triangle::vertex2 */
					else if(parent == parent->parent()->child(3)) {
						unsigned short index = 2;
						triangle->set_vertex(Sirat::Math::Vector(x,y,z),index);
					}
					break;
				}
				case quadrilateral_type: {
					unsigned int id = parent->parent()->child(0)->text(1).toUInt();
					Sirat::Object::Quadrilateral* quadrilateral = static_cast<Sirat::Object::Quadrilateral*>( scene->get_object(id));
					/* Triangle::vertex0 */
					if(parent == parent->parent()->child(1)) {
						unsigned short index = 0;
						quadrilateral->set_vertex(Sirat::Math::Vector(x,y,z),index);
					}
					/* Triangle::vertex1 */
					else if(parent == parent->parent()->child(2)) {
						unsigned short index = 1;
						quadrilateral->set_vertex(Sirat::Math::Vector(x,y,z),index);
					}
					/* Triangle::vertex2 */
					else if(parent == parent->parent()->child(3)) {
						unsigned short index = 2;
						quadrilateral->set_vertex(Sirat::Math::Vector(x,y,z),index);
					}
					/* Triangle::vertex3 */
					else if(parent == parent->parent()->child(4)) {
						unsigned short index = 3;
						quadrilateral->set_vertex(Sirat::Math::Vector(x,y,z),index);
					}
					break;
				}
				case punctual_light_type: {
					unsigned int id = parent->parent()->child(0)->text(1).toUInt();
					Sirat::Light::Punctual_Light* punctual_light = static_cast<Sirat::Light::Punctual_Light*>(scene->get_light(id));
					if(parent == parent->parent()->child(1)) {
						punctual_light->set_point(Sirat::Math::Vector(x,y,z));
					}
					break;
				}
				case square_light_type: {
					unsigned int id = parent->parent()->child(0)->text(1).toUInt();
					Sirat::Light::Square_Light* square_light = static_cast<Sirat::Light::Square_Light*>(scene->get_light(id));
					if(parent == parent->parent()->child(1)) {
						unsigned short index = 0;
						square_light->set_point(Sirat::Math::Vector(x,y,z),index);
					}
					if(parent == parent->parent()->child(2)) {
						unsigned short index = 1;
						square_light->set_point(Sirat::Math::Vector(x,y,z),index);
					}
					if(parent == parent->parent()->child(3)) {
						unsigned short index = 2;
						square_light->set_point(Sirat::Math::Vector(x,y,z),index);
					}
					if(parent == parent->parent()->child(4)) {
						unsigned short index = 3;
						square_light->set_point(Sirat::Math::Vector(x,y,z),index);
					}
					break;
				}
				default: break;
			}			
			break;
		}
	}
	parent = 0;
}

void Scene_Tree::reload_tree(void) {
	clear();
	insert_scene(scene);
}

void Scene_Tree::insert_scene(Sirat::Common::Scene* _scene) {
	scene = _scene;
	disconnect(this,SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(update_scene(QTreeWidgetItem*,int)));
	
	/* Scene attributes */
	Sirat::Common::Color background = _scene->get_background();
			
	addTopLevelItem(add_color(background,"background color"));
	addTopLevelItem(add_objectlist(_scene));
	addTopLevelItem(add_lightlist(_scene));
	
	connect(this,SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(update_scene(QTreeWidgetItem*,int)));
	connect(this,SIGNAL(itemClicked(QTreeWidgetItem*,int)),this,SLOT(show_information(QTreeWidgetItem*,int)));
}

Scene_Tree_Item * Scene_Tree::add_color(const Sirat::Common::Color& _color,const QString& _string) {
	Scene_Tree_Item* item = new Scene_Tree_Item(color_type);
	item->setText(0,_string);
	
	Scene_Tree_Item* r = new Scene_Tree_Item(value_type);
	r->setText(0,"r");
	r->setText(1,tr("%1").arg(_color.red));
	r->setFlags(r->flags() | Qt::ItemIsEditable);
	
	Scene_Tree_Item* g = new Scene_Tree_Item(value_type);
	g->setText(0,"g");
	g->setText(1,tr("%1").arg(_color.green));
	g->setFlags(g->flags() | Qt::ItemIsEditable);
	
	Scene_Tree_Item* b = new Scene_Tree_Item(value_type);
	b->setText(0,"b");
	b->setText(1,tr("%1").arg(_color.blue));
	b->setFlags(b->flags() | Qt::ItemIsEditable);
	
	item->addChild(r);
	item->addChild(g);
	item->addChild(b);
	
	return item;
}


Scene_Tree_Item* Scene_Tree::add_vector(const Sirat::Math::Vector& _vector,const QString& _string){
	Scene_Tree_Item* item = new Scene_Tree_Item(vector_type);
	item->setText(0,_string);
	
	Scene_Tree_Item* x = new Scene_Tree_Item(value_type);
	x->setText(0,"x");
	x->setText(1,tr("%1").arg(_vector.x));
	x->setFlags(x->flags() | Qt::ItemIsEditable);
	
	Scene_Tree_Item* y = new Scene_Tree_Item(value_type);
	y->setText(0,"y");
	y->setText(1,tr("%1").arg(_vector.y));
	y->setFlags(y->flags() | Qt::ItemIsEditable);
	
	Scene_Tree_Item* z = new Scene_Tree_Item(value_type);
	z->setText(0,"z");
	z->setText(1,tr("%1").arg(_vector.z));
	z->setFlags(z->flags() | Qt::ItemIsEditable);
	
	item->addChild(x);
	item->addChild(y);
	item->addChild(z);
	
	return item;
}


Scene_Tree_Item* Scene_Tree::add_objectlist(Sirat::Common::Scene* _scene){
	/* Objects */

	Scene_Tree_Item* item = new Scene_Tree_Item(objects_type);
	item->setText(0,"objects");
	
	Sirat::Object::Object* object;
	
	for(unsigned int i =0;i<_scene->get_objects_size();i++) {
		object = _scene->get_object(i);
		/* Sphere case */
		if(typeid(Sirat::Object::Sphere) == typeid(*object))
			item->addChild(add_sphere(static_cast<Sirat::Object::Sphere*> (object),i));
		/* Plane case */
		else if(typeid(Sirat::Object::Plane) == typeid(*object))
			item->addChild(add_plane(static_cast<Sirat::Object::Plane*> (object),i));
		/* Disc case */
		else if(typeid(Sirat::Object::Disc) == typeid(*object))
			item->addChild(add_disc(static_cast<Sirat::Object::Disc*> (object),i));
		/* Cone case */
		else if(typeid(Sirat::Object::Cone) == typeid(*object))
			item->addChild(add_cone(static_cast<Sirat::Object::Cone*> (object),i));
		/* Cylinder case */
		else if(typeid(Sirat::Object::Cylinder) == typeid(*object))
			item->addChild(add_cylinder(static_cast<Sirat::Object::Cylinder*> (object),i));
		/* Triangle case */
		else if(typeid(Sirat::Object::Triangle) == typeid(*object))
			item->addChild(add_triangle(static_cast<Sirat::Object::Triangle*> (object),i));
		/* Quadrilateral case */
		else if(typeid(Sirat::Object::Quadrilateral) == typeid(*object))
			item->addChild(add_quadrilateral(static_cast<Sirat::Object::Quadrilateral*> (object),i));
	}
	return item;
}


Scene_Tree_Item* Scene_Tree::add_sphere(Sirat::Object::Sphere* _sphere,unsigned int _id) {
	Sirat::Math::Vector center = _sphere->get_center();
	double radius = _sphere->get_radius();
	
	Scene_Tree_Item* item = new Scene_Tree_Item(sphere_type);
	item->setText(0,"sphere");
	
	Scene_Tree_Item* id_item = new Scene_Tree_Item();
	id_item->setText(0,"id");
	id_item->setText(1,tr("%1").arg(_id));
	
	Scene_Tree_Item* radius_item = new Scene_Tree_Item(value_type);
	radius_item->setText(0,"radius");
	radius_item->setText(1,tr("%1").arg(radius));
	radius_item->setFlags(radius_item->flags() | Qt::ItemIsEditable);
	
	item->addChild(id_item);
	item->addChild(radius_item);
	item->addChild(add_vector(center,"center"));
	
	return item;
}

Scene_Tree_Item* Scene_Tree::add_plane(Sirat::Object::Plane* _plane,unsigned int _id){
	Sirat::Math::Vector point = _plane->get_point();
	Sirat::Math::Vector normal = _plane->get_normal(Sirat::Math::Vector());

	Scene_Tree_Item* item = new Scene_Tree_Item(plane_type);
	item->setText(0,"plane");
	
	Scene_Tree_Item* id_item = new Scene_Tree_Item();
	id_item->setText(0,"id");
	id_item->setText(1,tr("%1").arg(_id));
	
	item->addChild(id_item);
	item->addChild(add_vector(point,"point"));
	item->addChild(add_vector(normal,"normal"));
	
	return item;
}

Scene_Tree_Item* Scene_Tree::add_disc(Sirat::Object::Disc* _disc,unsigned int _id){
	Sirat::Math::Vector center = _disc->get_center();
	Sirat::Math::Vector normal = _disc->get_normal(Sirat::Math::Vector());
	double radius = _disc->get_radius();

	Scene_Tree_Item* item = new Scene_Tree_Item(disc_type);
	item->setText(0,"disc");
	
	Scene_Tree_Item* id_item = new Scene_Tree_Item();
	id_item->setText(0,"id");
	id_item->setText(1,tr("%1").arg(_id));
	
	Scene_Tree_Item* radius_item = new Scene_Tree_Item(value_type);
	radius_item->setText(0,"radius");
	radius_item->setText(1,tr("%1").arg(radius));
	radius_item->setFlags(radius_item->flags() | Qt::ItemIsEditable);
	
	item->addChild(id_item);
	item->addChild(radius_item);
	item->addChild(add_vector(center,"center"));
	item->addChild(add_vector(normal,"normal"));
	
	return item;
}

Scene_Tree_Item* Scene_Tree::add_cone(Sirat::Object::Cone* _cone,unsigned int _id){
	Sirat::Math::Vector center = _cone->get_center();
	Sirat::Math::Vector direction = _cone->get_direction();
	double radius = _cone->get_radius();
	double height = _cone->get_height();

	Scene_Tree_Item* item = new Scene_Tree_Item(cone_type);
	item->setText(0,"cone");
	
	Scene_Tree_Item* id_item = new Scene_Tree_Item();
	id_item->setText(0,"id");
	id_item->setText(1,tr("%1").arg(_id));
	
	Scene_Tree_Item* radius_item = new Scene_Tree_Item(value_type);
	radius_item->setText(0,"radius");
	radius_item->setText(1,tr("%1").arg(radius));
	radius_item->setFlags(radius_item->flags() | Qt::ItemIsEditable);
	
	Scene_Tree_Item* height_item = new Scene_Tree_Item(value_type);
	height_item->setText(0,"height");
	height_item->setText(1,tr("%1").arg(height));
	height_item->setFlags(height_item->flags() | Qt::ItemIsEditable);
	
	item->addChild(id_item);
	item->addChild(radius_item);
	item->addChild(height_item);
	item->addChild(add_vector(center,"center"));
	item->addChild(add_vector(direction,"direction"));
	
	return item;
}

Scene_Tree_Item* Scene_Tree::add_cylinder(Sirat::Object::Cylinder* _cylinder,unsigned int _id){
	Sirat::Math::Vector center = _cylinder->get_center();
	Sirat::Math::Vector direction = _cylinder->get_direction();
	double radius = _cylinder->get_radius();
	double height = _cylinder->get_height();

	Scene_Tree_Item* item = new Scene_Tree_Item(cylinder_type);
	item->setText(0,"cylinder");
	
	Scene_Tree_Item* id_item = new Scene_Tree_Item();
	id_item->setText(0,"id");
	id_item->setText(1,tr("%1").arg(_id));
	
	Scene_Tree_Item* radius_item = new Scene_Tree_Item(value_type);
	radius_item->setText(0,"radius");
	radius_item->setText(1,tr("%1").arg(radius));
	radius_item->setFlags(radius_item->flags() | Qt::ItemIsEditable);
	
	Scene_Tree_Item* height_item = new Scene_Tree_Item(value_type);
	height_item->setText(0,"height");
	height_item->setText(1,tr("%1").arg(height));
	height_item->setFlags(height_item->flags() | Qt::ItemIsEditable);
	
	item->addChild(id_item);
	item->addChild(radius_item);
	item->addChild(height_item);
	item->addChild(add_vector(center,"center"));
	item->addChild(add_vector(direction,"direction"));
	
	return item;
}

Scene_Tree_Item* Scene_Tree::add_triangle(Sirat::Object::Triangle* _triangle,unsigned int _id){
	Sirat::Math::Vector vertices[3];
	for(unsigned short i = 0; i < 3; i++) vertices[i] = _triangle->get_vertex(i);

	Scene_Tree_Item* item = new Scene_Tree_Item(triangle_type);
	item->setText(0,"triangle");
	
	Scene_Tree_Item* id_item = new Scene_Tree_Item();
	id_item->setText(0,"id");
	id_item->setText(1,tr("%1").arg(_id));
	
	item->addChild(id_item);
	for(unsigned short i = 0; i < 3; i++) item->addChild(add_vector(vertices[i],tr("vertex %1").arg(i)));
	
	return item;
}

Scene_Tree_Item* Scene_Tree::add_quadrilateral(Sirat::Object::Quadrilateral* _quadrilateral,unsigned int _id){
	Sirat::Math::Vector vertices[4];
	for(unsigned short i = 0; i < 4; i++) vertices[i] = _quadrilateral->get_vertex(i);

	Scene_Tree_Item* item = new Scene_Tree_Item(quadrilateral_type);
	item->setText(0,"quadrilateral");
	
	Scene_Tree_Item* id_item = new Scene_Tree_Item();
	id_item->setText(0,"id");
	id_item->setText(1,tr("%1").arg(_id));
	
	item->addChild(id_item);
	for(unsigned short i = 0; i < 4; i++) item->addChild(add_vector(vertices[i],tr("vertex %1").arg(i)));
	
	return item;
}
Scene_Tree_Item* Scene_Tree::add_lightlist(Sirat::Common::Scene* _scene){
	/* Lights */
	Scene_Tree_Item* item = new Scene_Tree_Item(lights_type);
	item->setText(0,"lights");
	
	Sirat::Light::Light* light;
	
	for(unsigned int i = 0;i < _scene->get_lights_size();i++) {
		light = _scene->get_light(i);
		/* Punctual Light case */
		if(typeid(Sirat::Light::Punctual_Light) == typeid(*light))
			item->addChild(add_punctual_light(static_cast<Sirat::Light::Punctual_Light*> (light),i));
		/* Square Light case */
		else if(typeid(Sirat::Light::Square_Light) == typeid(*light))
			item->addChild(add_square_light(static_cast<Sirat::Light::Square_Light*> (light),i));
	}
	
	return item;
}

Scene_Tree_Item* Scene_Tree::add_punctual_light(Sirat::Light::Punctual_Light* _punctual_light,unsigned int _id){
	Sirat::Math::Vector origin = _punctual_light->get_point();

	Scene_Tree_Item* item = new Scene_Tree_Item(punctual_light_type);
	item->setText(0,"punctual light");
	
	Scene_Tree_Item* id_item = new Scene_Tree_Item();
	id_item->setText(0,"id");
	id_item->setText(1,tr("%1").arg(_id));
	
	item->addChild(id_item);
	item->addChild(add_vector(origin,"origin"));
	
	return item;
}

Scene_Tree_Item* Scene_Tree::add_square_light(Sirat::Light::Square_Light* _square_light,unsigned int _id){

	Sirat::Math::Vector points[4];
	for(unsigned short i = 0; i < 4; i++) points[i] = _square_light->get_point(i);
	
		
	Scene_Tree_Item* item = new Scene_Tree_Item(square_light_type);
	item->setText(0,"square light");
	
	Scene_Tree_Item* id_item = new Scene_Tree_Item();
	id_item->setText(0,"id");
	id_item->setText(1,tr("%1").arg(_id));
	
	item->addChild(id_item);
	for(unsigned short i = 0; i < 4; i++) item->addChild(add_vector(points[i],tr("point %1").arg(i)));
	return item;
}


}
